package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.DaoSchoolChildPageAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolChildSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolChildTopGetListAllDTO;
import com.sc.nft.entity.dto.DaoSchoolChildUpdateByIdAdminDTO;
import com.sc.nft.entity.vo.DaoSchoolChildPageAdminVO;
import com.sc.nft.service.DaoSchoolChildService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * dao学堂子分类表(DaoSchoolChild)表控制层
 *
 * @author makejava
 * @since 2023-03-13 16:21:56
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolChild")
@Api(tags = "dao学堂子分类")
public class DaoSchoolChildController {

    /**
     * 服务对象
     */
    private final DaoSchoolChildService daoSchoolChildService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolChildPageAdminVO> pageAdmin(@RequestBody @Validated DaoSchoolChildPageAdminDTO dto) {
        Page<DaoSchoolChildPageAdminVO> daoSchoolChildPageAdminVOPage = daoSchoolChildService.pageAdmin(dto);
        return PageResult.success(daoSchoolChildPageAdminVOPage);
    }

    @ApiOperation(value = "新增", notes = "新增", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@Validated @RequestBody DaoSchoolChildSaveAdminDTO daoSchoolChildSaveAdminDTO) {
        return PageResult.success(daoSchoolChildService.saveAdmin(daoSchoolChildSaveAdminDTO));
    }

    @ApiOperation(value = "根据id修改", notes = "根据id修改", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateByIdAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateByIdAdmin(@Validated @RequestBody DaoSchoolChildUpdateByIdAdminDTO daoSchoolChildUpdateByIdAdminDTO) {
        return PageResult.success(daoSchoolChildService.updateByIdAdmin(daoSchoolChildUpdateByIdAdminDTO));
    }

    @ApiOperation(value = "根据id删除这个分组", notes = "根据id删除这个分组", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteByIdAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteByIdAdmin(@Validated @RequestBody IdRequest idRequest) {
        return PageResult.success(daoSchoolChildService.deleteById(idRequest.getId()));
    }


    @ApiOperation(value = "根据父集ID获取子集列表", notes = "根据父集ID获取子集列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/selectByTopIdsGetListAll", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<DaoSchoolChildPageAdminVO>> selectByTopIdsGetListAll(@Validated @RequestBody DaoSchoolChildTopGetListAllDTO daoSchoolChildTopGetListAllDTO) {
        return Result.success(daoSchoolChildService.selectByTopIdsGetListAll(daoSchoolChildTopGetListAllDTO));
    }
}
